var express = require('express');
var router = express.Router();
const mongodb= require('../components/mongo');
const multer = require('multer');

var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'public/storage/27x318z')
  },
  filename: function (req, file, cb) {
    var fileFormat = (file.originalname).split(".");
    cb(null, file.fieldname + '-' + Date.now() + "." + fileFormat[fileFormat.length - 1]);
  }
})


const uploader = multer({storage:storage});

/* GET home page. */
// router.get('/',async function(req, res, next) {
//    console.log(req.query);
//    const result = await mongodb.find("User",{});
//    //res.json(result);
//    res.render('index',{title:'upload'})
// });

// router.post('/upload',uploader.single('avatar'),function(req,res,next){
// 	console.log(req.file);
// 	console.log(req.body);
// 	res.render('index', { title: 'Success' });
// })

module.exports = router;
